<template>
  <div class="question" @scroll="loading">
     <Loading v-if="this.$store.state.isLoading"></Loading>
    <div class="question_item" v-for="item in question" :key="item.id">
      <div class="tx">
        <img :src="`https://ss.lanqb.com/${item.profile.avatar}`" />
        <span>{{ item.profile.nickname }}</span>
      </div>
      <div class="title">
        <h3>{{ item.title }}</h3>
      </div>
      <div class="mid">
        <span>{{ item.content }}</span>
        <img
          v-for="img in item.works"
          :key="img.object_id"
          :src="`https://ss.lanqb.com/${img.url}`"
        />
      </div>
      <div class="bot">
        <div class="bot_tx">
          <img src="http://assets-cdn.lanqb.com/makesite.jpg" alt="" />
          <span class="nickname">{{ item.adopt_answer.nickname }}</span>
          <span class="caina">已采纳</span>
        </div>
        <div class="content">
          <span v-for="i in item.adopt_answer.content" :key="i.value">{{
            i.value
          }}</span>
          <a href="#">APP内查看</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Loading from "@/components/Loading.vue";
export default {
  name: "QuestionView",
components:{
  Loading
},
  data() {
    return {
      question: [],
      page: 1,
    };
  },

  mounted() {},
  created() {
    this.$store.commit("setLoading", true);
    this.$http({
      methods: "get",
      url: "/lqb/api/works/qa-list",
      params: {
        page: this.page,
      },
    }).then(({ data: data }) => {
      console.log(data);
      this.question = data.works;
    this.$store.commit("setLoading", false);

    });
  },

  methods: {
  async  loading(e) {
      if (e.target.scrollTop + e.target.clientHeight >= e.target.scrollHeight) {
        this.$store.commit("setLoading", true);
        this.page++;
    const {data}=await this.$http({
          methods: "get",
          url: "/lqb/api/works/qa-list",
          params: {
            page: this.page,
          },
        })
        console.log(data.works);
        this.question=[...this.question,...data.works];
        this.$store.commit("setLoading", false);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.question {
  width: 100vw;
  height: 73vh;
  overflow-y: scroll;
  .question_item {
    width: 100vw;
    display: flex;
    flex-direction: column;
    .tx {
      width: 85vw;
      margin: 20px auto 0px auto;
      display: flex;
      align-items: center;
      > img {
        width: 32px;
        height: 32px;
        border-radius: 50%;
      }
      > span {
        margin-left: 15px;
      }
    }
    .title {
      position: relative;
      margin-left: 40px;
      &::before {
        position: absolute;
        content: "\95EE";
        width: 20px;
        height: 20px;
        background: linear-gradient(324deg, #008bff, #006bfe);
        color: #fff;
        text-align: center;
        left: -13px;
        bottom: 1px;
        border-radius: 5px;
        font-size: 11px;
        line-height: 20px;
        opacity: 0.7;
      }
      h3 {
        padding-left: 10px;
        margin-top: 10px;
        color: #1a1b1e;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        width: 87%;
        font-weight: 400;
      }
    }
    .mid {
      margin-top: 10px;
      display: flex;
      > span {
        color: #5b6164;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        overflow: hidden;
        width: 70%;
        margin-left: 28px;
      }
      > img {
        width: 65px;
        height: 65px;
        border-radius: 5px;
      }
    }
    .bot {
      display: flex;
      flex-direction: column;
      width: 88%;
      margin: 10px auto;
      background-color: #f7f7f7;
      .bot_tx {
        margin: 10px;
        display: flex;
        align-items: center;
        > img {
          width: 20px;
          height: 20px;
          border-radius: 50%;
        }
        .nickname {
          margin-left: 5px;
          font-size: 13px;
          color: #3f4345;
        }
        .caina {
          margin-left: 3px;
          background: linear-gradient(90deg, #ffed70, #ffd865);
          text-align: center;
          color: #4c2915;
          font-size: 11px;
          display: inline-block;
          width: 53px;
          height: 20px;
          border-radius: 25px;
          line-height: 20px;
        }
      }
      .content {
        position: relative;
        margin-left: 10px;
        margin-bottom: 15px;
        > span {
          color: #5b6164;
          width: 80%;
        }
        > a {
          color: #008bff;
          position: absolute;
          font-size: 13px;
          right: 12px;
          bottom: 2px;
          background: #f7f7f7;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
